﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EdytorWF.Engine;
using EdytorWF.Objects;
using Docking = WeifenLuo.WinFormsUI.Docking;

namespace EdytorWF
{

    public partial class Edytor : Form
    {
        MainView EditorMainView;

        public Edytor()
        {
            InitializeComponent();

            EditorMainView = new MainView();
            
            MyDockPanel.Dock = DockStyle.None;
            EditorMainView.Show(MyDockPanel);
            IEditor.EditorInstance.ShowObjectDlg(MyDockPanel);
            IEditor.EditorInstance.ShowTypesDlg(MyDockPanel);
        }

        ~Edytor()
        {
            MyDockPanel.SaveAsXml("layout.xml");
        }

        /*Docking.IDockContent GetContentFromPersistString(String persistString)
        {
            if (persistString == EditorMainView.GetType().ToString())
                return EditorMainView;
            else if (persistString == ObjectsDialog.GetType().ToString())
                return ObjectsDialog;
            else
                return null;
        }*/

        
        private void Edytor_Resize(object sender, EventArgs e)
        {
            if (EditorMainView != null)
            {
                EditorMainView.Repaint();
            }
        }

        private void ToolWireFrame_Click(object sender, EventArgs e)
        {
            if (EditorMainView != null)
            {
                EditorMainView.SetWireFrame();
            }
        }

        private void ToolSolid_Click(object sender, EventArgs e)
        {
            if (EditorMainView != null)
            {
                EditorMainView.SetSolid();
            }
        }

        private void NormalMenu_Click(object sender, EventArgs e)
        {
            IEngine.EngineInstance.SetTypeView(EViewType.Editor);
        }

        private void NormalsMenu_Click(object sender, EventArgs e)
        {
            IEngine.EngineInstance.SetTypeView(EViewType.Normals);
        }

        private void ObjectDlgMenu_Click(object sender, EventArgs e)
        {
            IEditor.EditorInstance.ShowObjectDlg(MyDockPanel);
        }

        private void TypeDlgMenu_Click(object sender, EventArgs e)
        {
            IEditor.EditorInstance.ShowTypesDlg(MyDockPanel);
        }

        private void PutObjectButton_CheckedChanged(object sender, EventArgs e)
        {
            if (PutObjectButton.Checked)
            {
                PlaceObjectInCamera.Checked = false;
                SelectModeMenu.Checked = false;
                IEditor.EditorInstance.SetPutObjectMode();
                IEditor.EditorInstance.ActiveMode = EModes.CREATE_OBJECT;
            }
        }

        private void PlaceObjectInCamera_CheckedChanged(object sender, EventArgs e)
        {
            if (PlaceObjectInCamera.Checked)
            {
                PutObjectButton.Checked = false;
                SelectModeMenu.Checked = false;
                IEditor.EditorInstance.SetPlaceObjectInCamera();
                IEditor.EditorInstance.ActiveMode = EModes.CREATE_OBJECT;
            }
        }

        private void SelectModeMenu_CheckedChanged(object sender, EventArgs e)
        {
            if (SelectModeMenu.Checked)
            {
                PutObjectButton.Checked = false;
                PlaceObjectInCamera.Checked = false;
                IEditor.EditorInstance.ActiveMode = EModes.SELECT;
            }
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Created by Katarzyna Wereska & Paweł Burzyński");
        }

        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEditor.EditorInstance.Refresh();
        }

        private void fogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEngine.EngineInstance.SetTypeView(EViewType.Dof);
        }

        private void gamePreviewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEngine.EngineInstance.SetTypeView(EViewType.Game);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            IEngine.EngineInstance.Refresh();
        }
    }
}
